<?
for($x=0;$x<count($TransMMTableSource);$x++){
	$SQL[] = "
	INSERT INTO `$TransMMTableTarget` 
	(`ledger`, `ktrasl`, `tglbkt`,`nobkt`, `urut`, `noref`, `noorder`, `skada`, `debtur`, `debnam`, `untush`, `uraian`, `uraian_a` , `uraian_b` , `uraian_c` , `uraian_d`, `curr` , `jumlah`, `dk`, `rate`, `rupiah`, `princ`, `kdact`, `app1`,`app2`)
	
	SELECT LEDGER,KTRASL,TGLBKT,NOBKT,NORMUT,NOREF,NOORDER,SKADA,DEBTUR,DEBNAM,UNTUSH,
	       URAIAN,URAIAN1,URAIAN2,URAIAN3,URAIAN4,CURR,JUMLAH,DK,RATE,RUPIAH,'',UNTUSH,'1','1'
	FROM $SourceDB.{$TransMMTableSource[$x]}
	";
}

$SQL[] ="
UPDATE $TransMMTableTarget SET curr='IDR' WHERE curr='01';
";

$SQL[] ="
UPDATE $TransMMTableTarget SET curr='USD' WHERE curr='02';
";

$SQL[] ="
UPDATE $TransMMTableTarget SET noref=insert(noref,3,0,'0') WHERE (noref like 'BB%' or noref like 'BK%' or noref like 'TB%' or noref like 'TK%' or noref like 'ND%' or noref like 'NK%' or noref like 'MM%')
";

$SQL[] ="
UPDATE $TransMMTableTarget SET nobkt=insert(nobkt,3,0,'0')
";

/*
$SQL[] ="
UPDATE $TransMMTableTarget SET noref=insert(noref,7,0,'0') WHERE (noref like 'BB%' or noref like 'BK%' or noref like 'TB%' or noref like 'TK%' or noref like 'ND%' or noref like 'NK%' or noref like 'MM%')
";

$SQL[] ="
UPDATE $TransMMTableTarget SET nobkt=insert(nobkt,7,0,'0')
";
*/

/*
$SQL[] ="
UPDATE $TransMMTableTarget SET noref=concat(left(noref,2),'0',right(noref,LENGTH(noref)-2)) WHERE (noref like 'BB%' or noref like 'BK%' or noref like 'TB%' or noref like 'TK%' or noref like 'ND%' or noref like 'NK%' or noref like 'MM%')
";

$SQL[] ="
UPDATE $TransMMTableTarget SET nobkt=concat(left(nobkt,2),'0',right(nobkt,LENGTH(nobkt)-2)) WHERE (nobkt like 'BB%' or nobkt like 'BK%' or nobkt like 'TB%' or nobkt like 'TK%' or nobkt like 'ND%' or nobkt like 'NK%' or nobkt like 'MM%')
";
*/


//Execute Query MEssage
for($x=0;$x<count($SQL);$x++){
	$DBConnection->dbc->query($SQL[$x]);
//	print $SQL[$x]."<br>\n"; 
}
?>
